package com.svtar.ywg;

import android.app.Application;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheEntity;
import com.lzy.okgo.cache.CacheMode;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;
import com.svtar.ywg.constant.MyConstant;
import com.svtar.ywg.utils.SharedPreferencesUtils;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * Created by Svtar on 2019/1/23.
 */

public class MyApp extends Application {

    private static MyApp mMyApp;

    public static MyApp getInstance() {
        return mMyApp;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mMyApp = this;
        //网络框架初始化
        OkGo.getInstance().init(this)
                .setOkHttpClient(new OkHttpClient.Builder()
                        .readTimeout(MyConstant.OUT_TIME, TimeUnit.MILLISECONDS)
                        .writeTimeout(MyConstant.OUT_TIME, TimeUnit.MILLISECONDS)
                        .connectTimeout(MyConstant.OUT_TIME, TimeUnit.MILLISECONDS)
                        .build())
                .setCacheMode(CacheMode.NO_CACHE)
                .setCacheTime(CacheEntity.CACHE_NEVER_EXPIRE)
                .setRetryCount(1);
        SharedPreferencesUtils.init(this);
        //日志
        Logger.addLogAdapter(new AndroidLogAdapter());
    }

}
